function drawLine(x1,y1,x2,y2){
    canvas.moveTo(x1,y1);
    canvas.lineTo(x2,y2);
    canvas.stroke();
}
function distance(a,b){//计算距离
    return Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
function sitaGiver(rx,ry){//专门用来算角度
    let sita;//角度
    if(rx ==0) {//tan90度一生之敌
        sita = ry>0?Math.PI/2:-Math.PI/2;
    }else sita = Math.atan(ry/rx);
    if(sita == 0 && rx<0) sita = Math.PI;
    //sita 修正，因为tan函数的周期性只有一个PI
    if((rx<0&&ry<0)||(rx<0&&ry>0)) sita+=Math.PI;
    return sita;
}
var canvas = $("canvas")[0].getContext("2d");
var structure={
    floors:4,//层数
    floorPoints:[
        {x:0,y:0,id:0,width:4},
        {x:80,y:0,id:1,width:4},
        {x:0,y:80,id:2,width:4}],//楼梯节点
    floorConnections:[
        {from:0,to:1,width:5,classCounts:4,leftW:10,rightW:0},
        {from:0,to:2,width:5,classCounts:4,leftW:10,rightW:0}],
    floorHeight:40,//楼层高度，包括长轴
    population:52,
    classRoomMargin:3.5,
    floor:5,
    classWidth:10,
    init:function(){
        //生成第一层
        for(let i in this.floorConnections){
            let fi = this.floorConnections[i];
            for(let ii=1;ii<=this.floor;ii++){
                HallWay.newHallWay(fi.width,distance(this.floorPoints[fi.from],this.floorPoints[fi.to]),ii,
                this.floorConnections[i].from,this.floorConnections[i].to,testNewClassRoom(fi.classCounts,this.population),
                this.classRoomMargin,fi.leftW,fi.rightW);
            }
        }
        for(let i in this.floorPoints){
            let fi = this.floorPoints[i];
            for(let ii=0;ii<this.floor;ii++){
                Hole.newHole(fi.width,this.floorHeight,ii,fi.id);
            }
        }
    }
}

function run(){
    for(let i in HallWay.hallWay){
        if(HallWay.hallWay[i] == undefined) continue;
        for(let ii in HallWay.hallWay[i]){
            if(HallWay.hallWay[i][ii] == undefined) continue;
            HallWay.hallWayRun(HallWay.hallWay[i][ii]);
        }
    }
}
function disPlayOn(){
    canvas.fillStyle = "white";
    canvas.fillRect(0,0,3000,1000);
    let offSetX = 30;
    let offSetY = 30;
    let scale = 0.5;
    let ha = HallWay.hallWay[HallWay.hallWay.length-1];
    for(let i in ha){
        if(ha[i].floor != structure.floor) continue;
        let leftPoint = structure.floorPoints[ha[i].leftConnection];
        let rightPoint = structure.floorPoints[ha[i].rightConnection];
        if(leftPoint.y == rightPoint.y){
            if(leftPoint.x>rightPoint.x) {
                let cg = leftPoint;
                leftPoint = rightPoint;
                rightPoint = cg;
            }
            HallWay.displayHallWay(ha[i],offSetX+scale*leftPoint.x,offSetY+scale*leftPoint.y,scale*(rightPoint.x-leftPoint.x),false);
        }else{
            if(leftPoint.y>rightPoint.y) {
                let cg = leftPoint;
                leftPoint = rightPoint;
                rightPoint = cg;
            }
            HallWay.displayHallWay(ha[i],offSetX+scale*leftPoint.x,offSetY+scale*leftPoint.y,scale*(rightPoint.y-leftPoint.y),true);

        }
    }
}
var doubleMax = Math.pow(2,51);